@extends('default.mobile.layouts.companyPublic')
@if($type=='publish')
    @section('title','克隆职位-'.Site::get('webname'))
@else
    @section('title','编辑职位-'.Site::get('webname'))
@endif
{{--首页css--}}
@section('headcss')
    @parent
    <link rel="stylesheet" href="{{asset('/default/css/mobile/company/common.css')}}">
    <link rel="stylesheet" href="{{asset('/default/css/mobile/jquery/select.css')}}">
@endsection
{{--头部标签--}}
@if($type=='publish')
    @section('tag','克隆职位')
@else
    @section('tag','编辑职位')
@endif

{{--主体内容--}}
@section('content')
    <div class="fill" id="fill" style="overflow: hidden">
        <div class="form_info" id="form_info">
            <form action="@if($type=='publish'){{url('mobile/company/jobpublish')}}@else{{url('mobile/company/job/'.$companyJob->id.'/edit')}}@endif"
                  onsubmit="return checkJob('#jobForm')"  method="post" id="jobForm" name="jobForm">

                {{csrf_field()}}
                <dl>
                    <dt><strong>职位信息</strong></dt>
                    <dd></dd>
                </dl>
                <dl>
                    <dt>职位名称<span class="asterisk">*</span></dt>
                    <dd><input type="text" name="job_title" id="job_title"  value="{{$companyJob->job_title}}" placeholder="请输入职位名称" autocomplete="off"></dd>
                </dl>
                <dl class="arrow" id="part_status_select">
                    <input type="hidden" name="part_status" value="{{$companyJob->part_status}}" id="part_status" />
                    <dt>兼职状态</dt>
                    <dd><span class="select_text">请选择兼职状态</span></dd>
                </dl>
                <dl class="arrow" id="department_select">
                    <input type="hidden" name="department" value="{{$companyJob->department}}" id="department" />
                    <dt>招聘部门</dt>
                    <dd><span class="select_text">请选择招聘部门</span></dd>
                </dl>
                <dl class="arrow" id="industry_select">
                    <input type="hidden" name="industry" value="{{$companyJob->industry}}" id="industry" />
                    <dt>所属行业<span class="asterisk">*</span></dt>
                    <dd><span class="select_text">请选择所属行业</span></dd>
                </dl>
                <dl class="arrow" id="job_category_select">
                    <input type="hidden" name="job_category1" value="{{$companyJob->job_category1}}" id="job_category1" />
                    <input type="hidden" name="job_category2" value="{{$companyJob->job_category2}}" id="job_category2" />
                    <input type="hidden" name="job_category3" value="{{$companyJob->job_category3}}" id="job_category3" />
                    <input type="hidden" name="job_category4" value="{{$companyJob->job_category4}}" id="job_category4" />
                    <input type="hidden" name="job_category5" value="{{$companyJob->job_category5}}" id="job_category5" />
                    <dt>岗位类别<span class="asterisk">*</span></dt>
                    <dd><span class="select_text">请选择岗位类别</span></dd>
                </dl>
                <dl class="arrow" id="location_select">
                    <input name="location1" type="hidden" id="location1" value="{{$companyJob->location1}}">
                    <input name="location2" type="hidden" id="location2" value="{{$companyJob->location2}}">
                    <input name="location3" type="hidden" id="location3" value="{{$companyJob->location3}}">
                    <input name="location4" type="hidden" id="location4" value="{{$companyJob->location4}}">
                    <input name="location5" type="hidden" id="location5" value="{{$companyJob->location5}}">
                    <dt>工作地区<span class="asterisk">*</span></dt>
                    <dd><span class="select_text">请选择工作地区</span></dd>
                </dl>
                <dl>
                    <dt>招聘人数<span class="asterisk">*</span></dt>
                    <dd><input type="text" name="recruiting_num" id="recruiting_num"  value="{{$companyJob->recruiting_num}}"
                               placeholder="请输入招聘人数(0代表若干)" autocomplete="off"></dd>
                </dl>
                <dl class="arrow" id="salary_above_select">
                    <input type="hidden" name="salary_above" value="{{$companyJob->salary_above}}" id="salary_above" />
                    <dt>开始薪资<span class="asterisk">*</span></dt>
                    <dd><span class="select_text">请选择开始薪资</span></dd>
                </dl>
                <dl class="arrow" id="salary_below_select">
                    <input type="hidden" name="salary_below" value="{{$companyJob->salary_below}}" id="salary_below" />
                    <dt>结束薪资<span class="asterisk">*</span></dt>
                    <dd><span class="select_text">请选择待结束薪</span></dd>
                </dl>
                <dl class="arrow" id="welfare_select">
                    <input type="hidden" name="welfare" value="{{$companyJob->welfare}}" id="welfare" />
                    <dt>职位诱惑<span class="asterisk">*</span></dt>
                    <dd><span class="select_text">请选择职位诱惑</span></dd>
                </dl>
                <dl class="arrow" id="job_description">
                    <dt>职位描述<span class="asterisk">*</span></dt>
                    <dd>
                        <textarea name="description" id="description" style="display: none;">{{$companyJob->description}}</textarea>
                        <span class="select_text">@if(empty($companyJob->description))请输入职位描述@else{{$companyJob->description}}@endif</span>
                    </dd>
                </dl>
                <dl>
                    <dt><strong>条件限止</strong></dt>
                    <dd></dd>
                </dl>
                <dl class="arrow" id="education_select">
                    <input type="hidden" name="education" value="{{$companyJob->education}}" id="education" />
                    <dt>学历要求</dt>
                    <dd><span class="select_text">请选择学历</span></dd>
                </dl>
                <dl class="arrow" id="work_year_select">
                    <input type="hidden" name="work_year" value="{{$companyJob->work_year}}" id="work_year" />
                    <dt>相关经验</dt>
                    <dd><span class="select_text">请选择相关经验</span></dd>
                </dl>
                <dl class="arrow" id="gender_select">
                    <input type="hidden" name="gender" value="{{$companyJob->gender}}" id="gender" />
                    <dt>性别要求</dt>
                    <dd><span class="select_text">请选择性别</span></dd>
                </dl>
                <dl class="arrow" id="language_select">
                    <input type="hidden" name="language" value="{{$companyJob->language}}" id="language" />
                    <dt>语言能力</dt>
                    <dd><span class="select_text">请选择语言能力</span></dd>
                </dl>
                <dl class="arrow" id="age_above_select">
                    <input type="hidden" name="age_above" value="{{$companyJob->age_above}}" id="age_above" />
                    <dt>开始年龄</dt>
                    <dd><span class="select_text">请选择开始年龄</span></dd>
                </dl>
                <dl class="arrow" id="age_below_select">
                    <input type="hidden" name="age_below" value="{{$companyJob->age_below}}" id="age_below" />
                    <dt>结束年龄</dt>
                    <dd><span class="select_text">请选择结束年龄</span></dd>
                </dl>
                <dl>
                    <dt><strong>联系方式</strong></dt>
                    <dd></dd>
                </dl>
                <dl class="arrow" id="contact_info_select">
                    <input type="hidden" name="contact_info" value="{{$companyJob->contact_info}}" id="contact_info" />
                    <dt>联系方式<span class="asterisk">*</span></dt>
                    <dd><span class="select_text">请选择联系方式</span></dd>
                </dl>
                <div class="form_sub"><input type="submit" value="@if($type=='publish')克隆职位@else保 存@endif"></div>
            </form>
        </div>
    </div>
@endsection

@section('footerjs')
    @parent
    <script type="text/javascript" src="{{Resources::jsOption('company')}}"></script>
    <script type="text/javascript" src="{{asset('/default/js/mobile/jquery/jquery.select.js')}}"></script>
    <script type="text/javascript" src="{{asset('/default/js/mobile/jquery/jquery.select_many.js')}}"></script>
    <script type="text/javascript" src="{{asset('/default/js/mobile/jquery/jquery.select_position.js')}}"></script>
    <script type="text/javascript" src="{{asset('/default/js/mobile/jquery/jquery.select_welfare.js')}}"></script>
    <script type="text/javascript" src="{{Resources::jsOption(['expectedsalary'])}}"></script>
    <script type="text/javascript" src="{{Resources::jsProvinceArea()}}"></script>
    <script type="text/javascript" src="{{Resources::jsOnePosition()}}"></script>
    <script type="text/javascript" src="{{asset('/default/js/mobile/jquery/jquery.textarea.js')}}"></script>
    <script type="text/javascript" src="{{asset('/default/js/mobile/company/post_manage.js')}}"></script>
    <script type="text/javascript" src="{{asset('/default/js/mobile/jquery/zepto.scroll.js')}}"></script>

    <script>
        var _token =  '{{csrf_token()}}';
        var fill = $("#fill").find('#form_info');
        $(function(){
            //兼职状态
            fill.find("#part_status_select").select({
                select_title:'招聘部门',                //标题值
                hidden: '#part_status',                   //select隐藏表单值
                opt_data:option_part_status              //select选项值（数组json对象）
            });
            //部门不限
            var  opt_department = {!! $department !!};
            //console.log(opt_department)
            opt_department.unshift({'value':0,'text':'部门不限'});
            //招聘部门
            fill.find("#department_select").select({
                select_title:'招聘部门',                //标题值
                hidden: '#department',                   //select隐藏表单值
                opt_data:opt_department               //select选项值（数组json对象）
            });
            //所属行业
            fill.find("#industry_select").select({
                select_title:'所属行业',
                hidden: '#industry',
                opt_data:option_industry
            });
            //多选岗位类别
            fill.find("#job_category_select").select_position({
                select_title:'岗位类别',
                selectArr: ['#job_category1','#job_category2','#job_category3','#job_category4','#job_category5'],
                opt_position:option_position
            });
            //多选工作地区选择
            fill.find("#location_select").select_many({
                select_title:'工作地区',
                selectArr: ['#location1','#location2','#location3','#location4','#location5'],
                opt_city: (typeof(option_town) != 'undefined') ? option_town_second : (typeof(option_city) != 'undefined') ? option_city_two : [],
                opt_province:option_province
            });
            //薪资待遇
            fill.find("#salary_above_select").select({
                select_title:'开始薪资',
                hidden: '#salary_above',
                opt_data:option_expectedsalary
            });
            //薪资待遇2
            fill.find("#salary_below_select").select({
                select_title:'结束薪资',
                hidden: '#salary_below',
                opt_data:option_expectedsalary
            });
            //福利
            var comTemp = ["双休","包吃","包住","五险","公积金","年终奖","旅游","培训","带薪年假","节日礼物","定期体检","免费班车","加班补贴","交通补贴",
                "话费补贴","员工持股","岗位晋升","8小时工作制","项目提成","美女多","办公高大上","员工餐厅","健身房","活动室","配车"];
            var welfareArr=[];
            if(fill.find("#welfare_select").find('#welfare').val() != '' ){
                welfareArr = fill.find("#welfare_select").find('#welfare').val().split(",");
                for(var i=0;i<welfareArr.length;i++){
                    if($.inArray(welfareArr[i],comTemp) == '-1'){
                        comTemp.push(welfareArr[i]);
                    }
                }
            }
            fill.find("#welfare_select").select_welfare({
                select_title:'职位诱惑',
                hidden: '#welfare',
                opt_data: comTemp
            });
            //点击职位描述
            fill.find("#job_description").textarea({
                text_title:'职位描述',
                hidden: '#description'
            });
            //----------------------------------------------------------------------------------------------------------------------------------------
            //学历要求
            option_education.unshift({'value':'','text':'不限'});
            fill.find("#education_select").select({
                select_title:'学历要求',
                hidden: '#education',
                opt_data:option_education
            });
            //相关经验
            option_work_year.unshift({'value':'','text':'不限'});
            fill.find("#work_year_select").select({
                select_title:'相关经验',
                hidden: '#work_year',
                opt_data:option_work_year
            });
            //性别要求
            var option_gender = [{'value':'','text':'不限'},{'value':1,'text':'男'},{'value':2,'text':'女'}];
            fill.find("#gender_select").select({
                select_title:'性别要求',
                hidden: '#gender',
                opt_data:option_gender
            });
            //语言能力
            option_language.unshift({'value':'','text':'不限'});
            fill.find("#language_select").select({
                select_title:'语言能力',
                hidden: '#language',
                opt_data:option_language
            });
            //年龄
            var option_age=[{'value':'','text':'不限'}];
            for(var i=16;i<=64;i++) {
                option_age.push({'value':i,'text':i+'岁'});
            }
            fill.find("#age_above_select").select({
                select_title:'开始年龄',
                hidden: '#age_above',
                opt_data:option_age
            });
            fill.find("#age_below_select").select({
                select_title:'结束年龄',
                hidden: '#age_below',
                opt_data:option_age
            });
            //联系方式
            var option_contact = [
                {'value':'0','text':'使用基本资料'},
                {'value':1,'text':'使用当前部门'},
                {'value':2,'text':'使用独立联系方式'},
                {'value':3,'text':'保密只允许投递简历'}
            ];
            fill.find("#contact_info_select").select({
                select_title:'联系方式',
                hidden: '#contact_info',
                opt_data:option_contact,
                callback:function(val){
                    contact_info(val);
                }
            });
            //独立联系方式
            var val = fill.find("#contact_info_select").find("#contact_info").val();
            contact_info(val);
            //设置单选框的值
            if('{{old("contact_info")}}' == '2'){
                fill.find("#contact_info_select").find("#contact_info").val(2);
                fill.find("#contact_info_select").find(".select_text").html('使用独立联系方式');
                contact_info(2);
            }
        });
        /**
         * 独立联系方式
         * param val
         */
        function contact_info(val){
            if(val == '2'){
                if(fill.find('#contact').length <= 0){
                    var str = '';
                    str+='<div id="contact" class="contact">';
                    str+='<dl>';
                    str+='<dt>联系人<span class="asterisk">*</span></dt>';
                    str+='<dd><input type="text" name="contacts" id="contacts"  value="{{$companyBasic->contacts}}" placeholder="请输入联系人" autocomplete="off"></dd>';
                    str+='</dl>';
                    str+='<dl>';
                    str+='<dt>手机号码<span class="asterisk">*</span></dt>';
                    str+='<dd><input type="text" name="mobile" id="mobile"  value="{{$companyBasic->mobile}}" placeholder="请输入手机号码" autocomplete="off"></dd>';
                    str+='</dl>';
                    str+='<dl>';
                    str+='<dt>座机电话<span class="asterisk">*</span></dt>';
                    str+='<dd><input type="text" name="phone" id="phone"  value="{{$companyBasic->phone}}" placeholder="请输入座机电话" autocomplete="off"></dd>';
                    str+='</dl>';
                    str+='<dl>';
                    str+='<dt>传真号码</dt>';
                    str+='<dd><input type="text" name="fax" id="fax"  value="{{$companyBasic->fax}}" placeholder="请输入传真号码" autocomplete="off"></dd>';
                    str+='</dl>';
                    str+='</dl>';
                    str+='<dl>';
                    str+='<dt>Email</dt>';
                    str+='<dd><input type="text" name="email" id="email"  value="{{$companyBasic->email}}" placeholder="请输入Email" autocomplete="off"></dd>';
                    str+='</dl>';
                    str+='</div>';
                    fill.find("#contact_info_select").after(str);
                }
            }else{
                if(fill.find("#contact").length > 0){
                    fill.find("#contact").remove();
                }
            }
        }

        //错误信息提示
        @if(count($errors)>0)
            @if(is_object($errors))
                var msgErr='';
                @foreach($errors->all() as $error)
                        msgErr += "<p style='line-height: .4rem; width: 100%'>{{$error}};</p>";
                @endforeach
                layerMsg(msgErr,2);
            @endif
        @endif
        @if(auth()->guard('company')->user()->postNumber()<=0 && $type=='publish')
        layer.open({
                content: '您的职位数已用完或未开通vip会员？'
                ,btn: 'OK'
            });
        @endif
    </script>
@endsection